package com.skynet.supervision.controller.user;


import com.skynet.supervision.beans.request.user.*;
import com.skynet.supervision.beans.response.user.DeptUserItemResponse;
import com.skynet.supervision.beans.response.user.GetUserDetailsResponse;
import com.skynet.supervision.beans.response.user.UserItemResponse;
import com.skynet.supervision.common.PageResults;
import com.skynet.supervision.common.Result;
import com.skynet.supervision.common.ResultGeneric;
import com.skynet.supervision.services.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "人员管理")
@RestController
@RequestMapping(value = "/user")
public class UserInfoController {

    private final UserService userService;

    public UserInfoController(UserService userService) {
        this.userService = userService;
    }

    /**
     * 新增人员
     */
    @ApiOperation("新增人员")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid AddUserRequest request) {
        this.userService.add(request);
        return Result.success();
    }

    /**
     * 编辑人员信息
     */
    @ApiOperation("编辑人员信息")
    @PostMapping("/edit")
    public Result edit(@RequestBody @Valid EditUserRequest request) {
        this.userService.edit(request);
        return Result.success();
    }

    /**
     * 编辑人员信息
     */
    @ApiOperation("删除人员")
    @PostMapping("/delete")
    public Result delete(@RequestBody @Valid DeleteUserRequest request) {
        this.userService.delete(request.getUserId());
        return Result.success();
    }

    @ApiOperation("新增人员时的头像上传")
    @PostMapping("/uploadHeaderImg")
    public ResultGeneric<String> uploadHeaderImg(@RequestParam(value = "file")  MultipartFile file) {
        return ResultGeneric.success(this.userService.uploadHeaderImg(file));
    }


    /**
     * 获取人员信息
     */
    @ApiOperation("获取人员信息")
    @PostMapping("/getuser")
    ResultGeneric<GetUserDetailsResponse> getuser(@RequestBody GetDetailRequest request){
        return ResultGeneric.success(this.userService.getuser(request));
    }

    /**
     * 分页查询
     */
    @ApiOperation("分页查询")
    @PostMapping("/listByPage")
    ResultGeneric<PageResults<GetUserDetailsResponse>> listByPage(@RequestBody ListByPageRequest request){
        return ResultGeneric.success(PageResults.of(this.userService.listByPage(request)));
    }

//    /**
//     * 部门下拉列表
//     */
//    @ApiOperation("部门下拉列表")
//    @PostMapping("/deptList")
//    ResultGeneric<List<DeptItemResponse>> deptList(){
//        return ResultGeneric.success(this.userService.deptList());
//    }
//
//    /**
//     * 岗位下拉列表
//     */
//    @ApiOperation("岗位下拉列表")
//    @PostMapping("/deptPostList")
//    ResultGeneric<List<DeptPostItemResponse>> deptPostList(){
//        return ResultGeneric.success(this.userService.deptPostList());
//    }

    /**
     * 部门人员级联下拉
     */
    @ApiOperation("部门人员级联下拉")
    @PostMapping("/deptUserList")
    ResultGeneric<List<DeptUserItemResponse>> deptUserList(){
        return ResultGeneric.success(this.userService.deptUserList());
    }


    /**
     * 获取当前组内成员列表
     */
    @ApiOperation("获取当前组内成员列表")
    @PostMapping("/listByMyDeptUser")
    ResultGeneric<List<UserItemResponse>> listByMyDeptUser(){
        return ResultGeneric.success(this.userService.listByMyDeptUser());
    }

//    /**
//     * 根据部门id获取组内成员列表
//     */
//    @ApiOperation("根据部门id获取组内成员列表")
//    @PostMapping("/listByDeptId")
//    ResultGeneric<List<UserItemResponse>> listByDeptId(@RequestBody @Valid UserByDeptRequest request){
//        return ResultGeneric.success(this.userService.listByDeptId(request));
//    }



}
